
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/23/2012 16:04:03
-- Generated from EDMX file: G:\Projects\TrexSpace\TrexSpace.Shell\Models\TrexCore.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [sysrw];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Categories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Categories];
GO
IF OBJECT_ID(N'[dbo].[Posts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Posts];
GO
IF OBJECT_ID(N'[dbo].[UserAccounts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserAccounts];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Posts'
CREATE TABLE [dbo].[Posts] (
    [Id] nvarchar(100)  NOT NULL,
    [Title] nvarchar(max)  NULL,
    [Message] nvarchar(max)  NULL,
    [UserAccount_Account_Id] varchar(255)  NOT NULL,
    [Category_CategoryID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'UserAccounts'
CREATE TABLE [dbo].[UserAccounts] (
    [Account_Id] varchar(255)  NOT NULL,
    [Username] varchar(255)  NOT NULL,
    [ApplicationName] varchar(255)  NOT NULL,
    [Email] varchar(128)  NOT NULL,
    [Comment] varchar(255)  NULL,
    [Password] varchar(128)  NOT NULL,
    [PasswordQuestion] varchar(255)  NULL,
    [PasswordAnswer] varchar(255)  NULL,
    [IsApproved] bit  NULL,
    [LastActivityDate] datetime  NULL,
    [LastLoginDate] datetime  NULL,
    [LastPasswordChangedDate] datetime  NULL,
    [CreationDate] datetime  NULL,
    [IsOnLine] bit  NULL,
    [IsLockedOut] bit  NULL,
    [LastLockedOutDate] datetime  NULL,
    [FailedPasswordAttemptCount] int  NULL,
    [FailedPasswordAttemptWindowStart] datetime  NULL,
    [FailedPasswordAnswerAttemptCount] int  NULL,
    [FailedPasswordAnswerAttemptWindowStart] datetime  NULL
);
GO

-- Creating table 'Categories'
CREATE TABLE [dbo].[Categories] (
    [CategoryID] uniqueidentifier  NOT NULL,
    [Parent] nvarchar(max)  NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [PK_Posts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Account_Id] in table 'UserAccounts'
ALTER TABLE [dbo].[UserAccounts]
ADD CONSTRAINT [PK_UserAccounts]
    PRIMARY KEY CLUSTERED ([Account_Id] ASC);
GO

-- Creating primary key on [CategoryID] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [PK_Categories]
    PRIMARY KEY CLUSTERED ([CategoryID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserAccount_Account_Id] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_UserAccountPost]
    FOREIGN KEY ([UserAccount_Account_Id])
    REFERENCES [dbo].[UserAccounts]
        ([Account_Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAccountPost'
CREATE INDEX [IX_FK_UserAccountPost]
ON [dbo].[Posts]
    ([UserAccount_Account_Id]);
GO

-- Creating foreign key on [Category_CategoryID] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_CategoryPost]
    FOREIGN KEY ([Category_CategoryID])
    REFERENCES [dbo].[Categories]
        ([CategoryID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryPost'
CREATE INDEX [IX_FK_CategoryPost]
ON [dbo].[Posts]
    ([Category_CategoryID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------